<?php
namespace Cyfy\Modules\Translations\Forms;

use \Cyfy\Modules\Forms;
use \Cyfy\Modules\Translations\Module;

/**
 * Adds new language to database
 */
class AddLanguage extends Forms\Form
{
    function structure()
    {
        $this -> stay = false;
        $this -> permission("Translations", "administration");
   	
        $i = new Forms\TextBox("ownName", self :: t(430));
		$i -> required = true;
        $i -> description = self :: t(440);
		$this -> addItem($i);

        $i = new Forms\TextBox("englishName", self :: t(450));
        $i -> description = self :: t(460);
		$i -> required = true;
		$this -> addItem($i);
        
        $i = new Forms\TextBox("code", self :: t(410));
		$i -> required = true;
        $i -> description = self :: t(420);
		$i -> maxLength = 3;
		$this -> addItem($i);        
        
        $b = new Forms\Button(self :: t(470));
		$this -> addButton($b);
    }

    function submit()
    {
        $this -> onSubmit = "Cyfy.ajax('Translations', 'getLanguages', '#listOfLanguages');";
        \dibi :: query('INSERT INTO [:cyfy:Translations-languages] %v', $this->getAll());    
        \Cyfy\Message :: set(self :: t(481, array($this->get("ownName") . " (" . $this->get("englishName").")")));
        return true;
    }
  
}
